#define _CRT_SECURE_NO_WARNINGS 
/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) {
        vector<int> v;
        int k1 = 0, k2 = 0;
        while (l1)
        {
            l1 = l1->next;
            k1++;
        }
        while (l2)
        {
            l2 = l2->next;
            k2++;
        }
        long long n1, n2;
        while (k1--)
        {
            int m = 1;
            n1 += m * (l1->val);
            m *= 10;
        }
        while (k2--)
        {
            int m = 1;
            n2 += m * (l2->val);
            m *= 10;
        }
        long long sum = n1 + n2;
        int len = 0, len2 = sum;
        while (len2)
        {
            len2 /= 10;
            len++;
        }
        while (len--)
        {
            int m = sum % 10;
            v.insert(m);
        }
        reverse(v.begin(), v.end());
        for (auto e : v)
        {
            v->next = e;
        }
        return v;
    }
};